<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import = "java.util.*" %>
<%@ page import = "java.text.*" %>
<%@ page import = "com.alipay.api.*" %>
<%@ page import = "com.zhengke.pojo.*" %>
<%@ page import = "com.alipay.api.request.AlipayTradePagePayRequest" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
 </head>
<body>
	<%
		//根据提交的商品查询基本信息
		String title = "越南新娘";
		int count = 2;
		int price = 20000;
		int total = count * price;
		//订单号
		SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyyMMddHHmmss");
		String orderSn = simpledateformat.format(Calendar.getInstance().getTime());

		//向支付宝发起请求
		//获得初始化的AlipayClient
		AlipayClient alipayClient = new DefaultAlipayClient(AlipayEntity.gatewayUrl, AlipayEntity.app_id,
				AlipayEntity.merchant_private_key, "json", AlipayEntity.charset, AlipayEntity.alipay_public_key,
				AlipayEntity.sign_type);

		//设置请求参数
		AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
		alipayRequest.setReturnUrl(AlipayEntity.return_url);
		alipayRequest.setNotifyUrl(AlipayEntity.notify_url);

		//商户订单号，商户网站订单系统中唯一订单号，必填
		String out_trade_no = orderSn;
		//付款金额，必填
		String total_amount = total + "";
		//订单名称，必填
		String subject = title;
		//商品描述，可空
		String body = title + " * " + count;

		alipayRequest.setBizContent("{\"out_trade_no\":\"" + out_trade_no + "\"," + "\"total_amount\":\""
				+ total_amount + "\"," + "\"subject\":\"" + subject + "\"," + "\"body\":\"" + body + "\","
				+ "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}");

		//请求
		String result = "";
		try {
			result = alipayClient.pageExecute(alipayRequest).getBody();
		} catch (AlipayApiException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		//输出
		out.println(result);
	%>
</body>
</html>